﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sprout.Repository.Template.XParseEngine
{
    internal class DeSerializerFactory
    {
        public const string ELEMENT_DYNAMIC = "dynamic";
        public const string ELEMENT_ISEQUAL = "isequal";
        public const string ELEMENT_ISNOTEQUAL = "isnotequal";
        public const string ELEMENT_ISGREATEREQUAL = "isgreaterequal";
        public const string ELEMENT_ISGREATERTHAN = "isgreaterthan";
        public const string ELEMENT_ISLESSEQUAL = "islessequal";
        public const string ELEMENT_ISLESSTHAN = "islessthan";
        public const string ELEMENT_ISNOTEMPTY = "isnotempty";
        public const string ELEMENT_ISEMPTY = "isempty";
        public const string ELEMENT_ISNOTNULL = "isnotnull";
        public const string ELEMENT_ISNULL = "isnull";

        private readonly IDictionary<string, IDeSerializer> serializerMap = new Dictionary<string, IDeSerializer>();
        public DeSerializerFactory()
        {
            this.serializerMap.Add("dynamic", new DynamicDeSerializer());
            this.serializerMap.Add("isequal", new IsEqualDeSerializer());
            this.serializerMap.Add("isnotequal", new IsNotEqualDeSerializer());
            this.serializerMap.Add("isgreaterequal", new IsGreaterEqualDeSerializer());
            this.serializerMap.Add("isgreaterthan", new IsGreaterThanDeSerializer());
            this.serializerMap.Add("islessequal", new IsLessEqualDeSerializer());
            this.serializerMap.Add("islessthan", new IsLessThanDeSerializer());
            this.serializerMap.Add("isnotempty", new IsNotEmptyDeSerializer());
            this.serializerMap.Add("isempty", new IsEmptyDeSerializer());
            this.serializerMap.Add("isnotnull", new IsNotNullDeSerializer());
            this.serializerMap.Add("isnull", new IsNullDeSerializer());
        }
        public IDeSerializer GetDeSerializer(string id)
        {
            if (this.serializerMap.ContainsKey(id))
            {
                return this.serializerMap[id];
            }
            throw new Exception("There's no dynamic tag DeSerializer with id '" + id + "', cause: there's no valid dynamic tag named '" + id);
        }
    }
}
